# coding=utf-8
import requests

session = requests.Session()  # 实例化session

# 使用session发送post请求， 对方服务器会把cookie设置在session中
headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36"
}
post_url = "http://www.renren.com/PLofin.do"
post_data = {"email": "13146128763", "password": "zhoudawei123"}

session.post(post_url, data=post_data, headers=headers)

# 请求个人主页，会带上之前的cookie，能够请求成功
profile_url = "http://www.renren.com/941954027/profile"

response = session.get(profile_url, headers=headers)

with open("renren.html", "w", encoding="utf-8") as f:
    f.write(response.content.decode())


# 通过requests模块获取cookie
# url = "https://www.baidu.com"
# response = requests.get(url)
# cookies = requests.utils.dict_from_cookiejar(response.cookies)
# print(cookies)

